<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>提现</title>
		<meta name="Description" content="" />
		<meta name="Keywords" content="" />
		<meta name="format-detection" content="telephone=no, email=no" />
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<!-- 忽略页面中的数字识别为电话，忽略email识别 -->
		<meta name="applicable-device" content="mobile" />
		<meta name="apple-mobile-web-app-title" content="" />
		<!-- 添加到主屏后的标题（iOS 6 新增） -->
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<!-- 是否启用 WebApp 全屏模式 -->
		<meta name="HandheldFriendly" content="true" />
		<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
		<meta name="author" content="Jack" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="../../js/flexible.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../../style/jquery_css/weui.css" />
		<link rel="stylesheet" type="text/css" href="../../style/jquery_css/jquery-weui.css" />
		<link rel="stylesheet" type="text/css" href="../../swiper/css/swiper.min.css" />
		<link rel="stylesheet" type="text/css" href="../../style/public.css" />
		<link rel="stylesheet" type="text/css" href="../../style/icon_font/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../../style/main.css" />
		<link rel="stylesheet" type="text/css" href="../../style/icon.css" / <link rel="stylesheet" type="text/css" href="../../style/car.css" />
	</head>

	<body class="body-bg">
		<div class="header-nav is-postion">
			<div class="cen-mony">
				<div class="header-flex">
					<i class="return-2" onclick="window.history.go(-1)"></i>
				</div>
				<div class="header-flex">提现</div>
				<div class="header-flex"></div>
			</div>
		</div>
		<div class="UDC-max-box">
			<div class="top-my-UDC" style="padding-bottom: 0;">

				<ul class="MUDC-ul">
					<li class="border-topp">
						<div class="inile-block this_font">当前余额</div>
						<div class="inile-block float-tib" id="this-money"></div>
					</li>
					<li class="border-topp">
						<div class="inile-block this_font">提现金额</div>
						<div class="inile-block float-tib">
							<input type="number" placeholder="请输入提现金额" class="TB-num" id="account-money" />
						</div>
					</li>
					<li class="border-topp">
						<div class="inile-block this_font">手续费率</div>
						<div class="inile-block float-tib" id="rate"></div>
					</li>
					<li>
						<div class="inile-block this_font">到账金额</div>
						<div class="inile-block float-tib" id="account-sum">0.00</div>
					</li>

				</ul>

			</div>
		</div>

		<div class="top-MUDC">
			<ul class="MUDC-ul cen-ul">

				<li class="border-topp " onclick="main_obj.select_blank()">
					<div class="inile-block this_font">开户银行</div>
					<div class="inile-block float-tib"><span id="blank-name"></span><i class="iconfont icon-you"></i></div>
				</li>
				<li class="border-topp">
					<div class="inile-block this_font">银行账号</div>
					<div class="inile-block float-tib">
						<input type="number" placeholder="请输入银行账号" class="TB-num" id="blank-num" />
					</div>
				</li>
				<li class="border-topp">
					<div class="inile-block this_font">开户名</div>
					<div class="inile-block float-tib" id="blank-user"></div>
				</li>
				<li class="border-topp">
					<div class="inile-block this_font">手机号</div>
					<div class="inile-block float-tib" id="blank-phone"></div>
					<input type="hidden" id="blank-phone-hide" value="" />
				</li>
				<li class="border-topp">
					<div class="inile-block this_font">
						<input type="text" placeholder="请输入验证码" class="TB-num" style="text-align: left;" id="code"/>
					</div>
					<div class="inile-block float-tib">
						<span class="code-span" style="width: 100%;">
							<button class="code-get"  id="get-code-my" onclick="main_obj.get_code()">获取验证码</button>
						</span>
					</div>
				</li>
			</ul>

			<div class="TB-box">
				<button class="sbmit-btn" style="width: 100%;" onclick="main_obj.submit_fn()">提现</button>
			</div>
		</div>
		<div class="select_box select_box3"></div>
	</body>
	<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/weiUI/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/api/api_url.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/api/port_url.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../swiper/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/dySelect.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var user_arr = JSON.parse(sessionStorage.getItem('users_info'));
		$(function() {
			main_obj.tx_config();
			main_obj.user_info();
		})

		var html = '';
		var hgS3 = new selectSwiper({
			el: '.select_box3',
			mustSelect: true,
			activeIndex: 0,
			data: ['工商银行', '中国银行', '农业银行', '建设银行', '招商银行', '交通银行'],
			init: function(index) {
				if(index !== -1) {
					$('#blank-name').html(this.data[index]);
				}
			},
			okFunUndefind: function() {
				//alert('必须选择一项');
				return false;
			},
			okFun: function(index) {
				$('#blank-name').html(this.data[index]);
			},
			closeFun: function() {
				console.log('取消');
			},
		});
		var main_obj = {
			select_blank: function() {
				hgS3.openSelectSwiper();
			},
			tx_config: function() {
				$.ajax({
					url: config_URL.api + URL.txConfig, //请求的url地址
					dataType: "json", //返回格式为json
					data: {
						access_token: '41ab23e7efb238797fe39cc30f6b21d3',
						user_token: user_arr.user_token,
						user_id: user_arr.id
					},
					type: "POST", //请求方式
					success: function(res) {
						console.log(res);
						var data = res.data;
						//var banklist = res.data.banklist;
						if(res.code == 0) {
							$('#rate').html(data.config.sxf);
						} else {
							$.toast(res.msg, "text");
						}

					},
					error: function(rul) {
						console.log('网络出错')
					}
				});
			},
			submit_fn: function() {
				var money_user = $.trim($('#account-money').val());
				var balance = parseInt($('#this-money').text());

				if(money_user == '') {
					$.toast("请输入提现金额!", "text");
					return false;
				}
				if(money_user % 100 !== 0) {
					$.toast("提现金额必须为100的倍数!", "text");
					return false;
				}
				if(money_user < 100) {
					$.toast("提现单笔最小为100", "text");
					return false;
				}
				if(money_user > balance) {
					$.toast("提现金额不能大于当前余额！", "text");
					return false;
				}
				if(money_user > balance) {
					$.toast("提现金额不能大于当前余额！", "text");
					return false;
				}

				if($.trim($('#blank-num').val()) == '') {
					$.toast("请输入银行账号!", "text");
					return false;
				}
				if($.trim($('#code').val()) == '') {
					$.toast("请输入验证码!", "text");
					return false;
				}
				$.ajax({
					url: config_URL.api + URL.applyTx, //请求的url地址
					dataType: "json", //返回格式为json
					data: {
						access_token: '41ab23e7efb238797fe39cc30f6b21d3',
						user_token: user_arr.user_token,
						user_id: user_arr.id,
						money:$('#account-money').val(),
						bank:$('#blank-num').val(),
						bankUser:$('#blank-user').html(),
						phone:$('#blank-phone-hide').val(),
						code:$('#code').val(),
						bankName:$('#blank-name').html()
					},
					type: "POST", //请求方式
					success: function(res) {
						console.log(res);
						var data = res.data;
						if(res.code == 0) {
							$.toast('提现申请已提交！', "text");
							setTimeout(function(){
								window.location.href = '../my/my.html'
							},2000)
						} else {
							$.toast(res.msg, "text");
						}

					},
					error: function(rul) {
						console.log('网络出错')
					}
				});
			},
			//用户信息
			user_info: function() {
				$.ajax({
					url: config_URL.api + URL.userInfo, //请求的url地址
					dataType: "json", //返回格式为json
					data: {
						access_token: '41ab23e7efb238797fe39cc30f6b21d3',
						user_token: user_arr.user_token,
						user_id: user_arr.id
					},
					type: "POST", //请求方式
					success: function(res) {
						console.log(res)
						var data = res.data;
						if(res.code == 0) {
							$('#this-money').html(data.moneyMy);
							$('#blank-user').html(data.name);
							function geTel(tel){
						    	var reg = /^(\d{3})\d{4}(\d{4})$/;  
						    	return tel.replace(reg, "$1****$2");
							}
							$('#blank-phone').html(geTel(data.phone));
							$('#blank-phone-hide').val(data.phone);
						} else {
							$.toast(res.msg, "text");
						}

					},
					error: function(rul) {
						console.log('网络出错')
					}
				});
			},
			//获取验证码
			get_code: function() {
				$.showLoading(' ');
				$.ajax({
					url: config_URL.api + URL.send, //请求的url地址
					dataType: "json", //返回格式为json
					data: {
						access_token: 'a7fa17645ff7f03cd90b292cf96fa535',
						phone: $('#blank-phone-hide').val(),
						type:'4'
					},
					type: "POST", //请求方式
					success: function(res) {
						console.log(res)
						if(res.code == 0) {
							$.hideLoading();
							$.toast("验证码已发送!", "text");
							$("#get-code-my").addClass("on");
							var time = 60;
							$("#get-code-my").attr("disabled", true);
							var timer = setInterval(function() {
								if(time == 0) {
									clearInterval(timer);
									$("#get-code-my").attr("disabled", false);
									$("#get-code-my").text("获取验证码");
									$("#get-code-my").removeClass("on");
								} else {
									$('#get-code-my').text(time + "s重新获取");
									time--;
								}
							}, 1000);
						} else {
							$.toast(res.msg, "text");
						}

					},
					error: function(rul) {
						console.log('网络出错')
					}
				});
			},
		}
		$("#account-money").on('input propertychange', function() {
			if($.trim($('#account-money').val()) >= 100) {
				var account_money_str = $("#account-money").val();
				var rate = $('#rate').text();
				$('#account-sum').html(account_money_str - (account_money_str * rate));
			} else {
				$('#account-sum').html('0.00')
			}
		})
	</script>

</html>